const WXAPI = require('apifm-wxapi')
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    orderId: 0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      orderId : options.orderId
    })                                                                                                                                              
  },


  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  bindCancel: function () {
    wx.navigateBack({})
  },

  // 提交评价
  async evaluate(e) {
    var that = this;
    var commentValue = e.detail.value.commentValue;
    
    var orderCommentInfo = {
      'fruitOrderId': this.data.orderId,
      'commentValue': commentValue,
      'userId': wx.getStorageSync('userid')
    }
    console.log("评论信息："+JSON.stringify(orderCommentInfo))
    const res = await WXAPI.addComment(orderCommentInfo);
    console.log("评论结果："+JSON.stringify(res))
    if(res.code == 20000){
      wx.showModal({
        title: '成功',
        content: '评论提交成功',
        showCancel: false
      })
    }else{
      wx.showModal({
        title: '评价提交失败',
        content: res.msg,
        showCancel: false
      })
    }
  }
})